package com.jiaolong.controller;

import com.jiaolong.dto.OrderDto;
import com.jiaolong.service.JiaolongpayService;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;

@Slf4j
@RestController
@RequestMapping("/api/jiaolongpay")
public class JiaolongpayController {

    @Resource
    private JiaolongpayService jiaolongpayService;

    /**
     * 将订单信息存入数据库，生成支付二维码
     */
    @PostMapping("/getQRCode")
    public void getQRCode(@RequestBody OrderDto orderDto, HttpServletResponse servletResponse) {
        log.info("订单参数: {}", orderDto.toString());
        jiaolongpayService.getQRCode(orderDto, servletResponse);

    }

    /**
     * 用户扫描二维码跳转对应支付页面
     * @param request 客户端扫描二维码发起请求
     * @return
     */
    @GetMapping("/payScanCode/{mchOrderNo}")
    public void payScanCode(@PathVariable Long mchOrderNo, HttpServletRequest request, HttpServletResponse response) {
        log.info("用户已扫码, 订单号：{}", mchOrderNo);
        jiaolongpayService.paymentWay(mchOrderNo, request, response);
    }
}
